package google._2016.roundC;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;

public class GFiles {
	
	private static final BigInteger ONEH = BigInteger.valueOf(100);
	private static final BigInteger BIGNUM = new BigInteger("10000000000000000");
	//private static final BigInteger GATE = BigInteger.valueOf(10);
	
	private static class Area {
		BigInteger left;
		BigInteger right;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("resources/B-small-attempt0.in"));
        FileWriter out = new FileWriter("resources/B-small-attempt0.out");
        int T = Integer.valueOf(in.readLine().trim());
        for(int i = 1; i <= T; i++) {
            out.write("Case #" + i + ": ");
            run(in, out);
            out.write("\n");
        }
        in.close();
        out.flush();
        out.close();
	}
	
	private static void run(BufferedReader in, FileWriter out) throws NumberFormatException, IOException {
		int parts = Integer.valueOf(in.readLine().trim());
		Area ans = new Area();
		ans.left = BigInteger.ZERO;
		ans.right = BIGNUM;
		
		for (int i = 0; i < parts; i++) {
			String[] tmps = in.readLine().trim().split(" ");
			if (ans.left.compareTo(ans.right) > 0)
				continue;
			
			Area other = getArea(tmps[0], tmps[1]);
			ans = joinArea(ans, other);
		}
		
		if (ans.left.compareTo(ans.right) == 0)
			out.write(ans.left.toString());
		else
			out.write("-1");
	}
	
	private static Area getArea(String percent, String count) {
		BigInteger up = new BigInteger(count).multiply(ONEH);
		BigInteger downLeft = new BigInteger(percent).add(BigInteger.ONE);
		BigInteger downRight = new BigInteger(percent);
		Area result = new Area();
		if (downRight.equals(BigInteger.ZERO))
			result.right = BIGNUM;
		else
			result.right = up.divide(downRight);
		result.left = up.divide(downLeft).add(BigInteger.ONE);
		return result;
	}
	
	private static Area joinArea(Area a, Area b) {
		Area result = new Area();
		result.left = (a.left.compareTo(b.left) > 0)? a.left : b.left;
		result.right = (a.right.compareTo(b.right) < 0)? a.right : b.right;
		return result;
	}

}
